package winOrDie.GameEngine.Client;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import rice.p2p.commonapi.Node;

import winOrDie.Net.Client.WoD_Client_ControlChannel;
import winOrDie.Net.Client.WoD_Client_ControlChannel_Event;
import winOrDie.Net.Client.WoD_Client_ControlChannel_Listener;
import winOrDie.Net.Client.WoD_Client_RT;
import winOrDie.Net.Client.WoD_Client_RT_Event;
import winOrDie.Net.Client.WoD_Client_RT_Listener;
import winOrDie.Net.Client.WoD_Peers_List;
import winOrDie.Net.P2P.WoD_Scribe_Channel;

public class WoD_Client 
implements WoD_Client_ControlChannel_Listener, WoD_Client_RT_Listener
{

	
	private WoD_Peers_List woDClientPeersList = null;;
	private Socket socket = null;
	
	private WoD_Client_ControlChannel woDClientControlChannel = null;
	private WoD_Client_RT woDClientRT = null;
	
	
	
	
	public WoD_Peers_List getWoDClientPeersList() {
		return woDClientPeersList;
	}

	public Socket getSocket() {
		return socket;
	}

	public WoD_Client_ControlChannel getWoDClientControlChannel() {
		return woDClientControlChannel;
	}

	public WoD_Client_RT getWoDClientRT() {
		return woDClientRT;
	}

	public WoD_Client(Node node) {
		woDClientPeersList = new WoD_Peers_List();
		woDClientControlChannel = new WoD_Client_ControlChannel(node);
	}

	
	
	public void connectToWoDServer(String hostName, int port) throws Exception
	{
		try {
			socket = new Socket(hostName, port);
		} catch (UnknownHostException e) {
			Exception exception = new Exception("Unknown host: " + hostName + ". " + e.getMessage());
			throw exception;
			
		} catch (IOException e) {
			Exception exception = new Exception("IO Error. " + e.getMessage());
			throw exception;
		}
		
		try {
			woDClientControlChannel = new WoD_Client_ControlChannel(socket);
			woDClientControlChannel.add_WoD_Client_ControlChannel_Listener(this);

		} catch (Exception e) {
			Exception exception = new Exception("Error on control channel. " + e.getMessage());
			throw exception;
		}
		
		
	}
	
	
	
	public void notify_Event_WoD_Client_ControlChannel(
			WoD_Client_ControlChannel_Event event) {
		switch (event.getEvent_Type()) {
		
		case WoD_Client_ControlChannel_Event.CLIENT_ERROR:
			
			break;
			
		case WoD_Client_ControlChannel_Event.JOIN_GAME_KO:
			
			break;
			
		case WoD_Client_ControlChannel_Event.JOIN_GAME_OK:
			
			break;
			

		default:
			break;
		}
		
	}
	
	
	
	public void notify_Event_WoD_Client_RTChannel(WoD_Client_RT_Event event) {
		switch (event.getEvent_Type()) {
		case WoD_Client_RT_Event.GAME_ACTION:
			
			break;

		default:
			break;
		}
		
	}
	
}
